package com.hilihili.config;

import com.hilihili.transcode.AbstractTranscodeCommand;
import com.hilihili.transcode.CUDACommand;
import com.hilihili.transcode.MixtureCUDACommand;
import com.hilihili.transcode.NoneCommand;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;

/**
 * ffmpeg 根据配置文件自动配置相应执行命令
 * @author machi
 * @date 2024/01/31
 */
@Configuration
public class CommandConfiguration {

    @Autowired
    private TranscodeConfig transcodeConfig;

    @Bean
    @ConditionalOnProperty(name = "transcode-config.DXVAType", havingValue = "cuda")
    @Primary
    public AbstractTranscodeCommand cudaCommand() {
        return new CUDACommand(transcodeConfig);
    }

    @Bean
    @ConditionalOnProperty(name = "transcode-config.DXVAType", havingValue = "none")
    @Primary
    public AbstractTranscodeCommand noneCommand() {
        return new NoneCommand(transcodeConfig);
    }

    @Bean
    @ConditionalOnProperty(name = "transcode-config.DXVAType", havingValue = "mixture-cuda")
    @Primary
    public AbstractTranscodeCommand mixtureCUDACommand() {
        return new MixtureCUDACommand(transcodeConfig);
    }

    @Bean
    public AbstractTranscodeCommand defaultCommand() {
        return new NoneCommand(transcodeConfig);
    }
}
